# Maintainer: Patrick Gansterer <paroga@paroga.com>
pkgname=thrift
pkgver=0.20.0
pkgrel=1
pkgdesc="Language-independent software stack for RPC implementation"
url="https://thrift.apache.org/"
arch="all"
license="Apache-2.0"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	libevent-dev
	"
makedepends="
	bison
	boost-dev
	cmake
	flex
	glib-dev
	libevent-dev
	qt5-qtbase-dev
	openssl-dev
	samurai
	zlib-dev
	"
subpackages="
	$pkgname-dev
	lib$pkgname:lib
	lib${pkgname}nb:libnb
	lib${pkgname}z:libz
	lib$pkgname-glib:libglib
	lib$pkgname-qt:libqt
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/apache/thrift/archive/v$pkgver.tar.gz
	skip-old-tls-tests.patch
	"

# secfixes:
#   0.14.0-r0:
#     - CVE-2020-13949

build() {
	cmake -B _build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=ON \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		-DWITH_AS3=OFF \
		-DWITH_JAVA=OFF \
		-DWITH_JAVASCRIPT=OFF \
		-DWITH_NODEJS=OFF \
		-DWITH_PYTHON=OFF
	cmake --build _build
}

check() {
	local skipped_tests="(StressTestConcurrent|StressTestNonBlocking"
	local tests="
		testapplicationexception
		testtransportsocket
		testbinaryprotocol
		testcompactprotocol
		testbufferedtransport
		testframedtransport
		testfdtransport
		testsimpleserver
		testdebugproto
		testthriftbinaryreadcheck
		testthriftbufferedreadcheck
		testthriftcompactreadcheck
		testthriftframedreadcheck
		testthriftfdreadcheck
		testzlibtransport
		testthrifttestzlibclient
		"
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)"
	ctest --test-dir _build --output-on-failure -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install _build
}

lib() {
	amove usr/lib/libthrift.so.*
}

libglib() {
	amove usr/lib/libthrift_c_glib*.so.*
}

libnb() {
	amove usr/lib/libthriftnb.so.*
}

libqt() {
	amove usr/lib/libthriftqt5.so.*
}

libz() {
	amove usr/lib/libthriftz.so.*
}

sha512sums="
5e4ee9870b30fe5ba484d39781c435716f7f3903793dc8aae96594ca813b1a5a73363b84719038ca8fa3ab8ef0a419a28410d936ff7b3bbadf36fc085a6883ae  thrift-0.20.0.tar.gz
09c9dd046e66ce8897580db3671180ef44520c53a151cd2f2cd9db7900245f3c7b14a58de5842e1e785497a6f0348d2161af29affd06d041234bcf3a91870b8d  skip-old-tls-tests.patch
"
